package movee.domain.constants;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 操作单影响程度
 *
 * @author movee
 */
@Getter
@AllArgsConstructor
public enum BackupTaskType {

    GLOBAL(1, "全局任务", ""),
    BATCH(2, "批量任务", ""),
    SINGLE(3, "实时任务", "");


    private final int id;
    private final String chineseName;
    private final String description;

    private static final Map<String, BackupTaskType> CHINESE_MAP = new HashMap<>();
    private static final Map<String, BackupTaskType> NAME_MAP = new HashMap<>();
    private static final Map<Integer, BackupTaskType> ID_MAP = new HashMap<>();

    static {
        for (BackupTaskType type : BackupTaskType.values()) {
            CHINESE_MAP.put(type.getChineseName(), type);
            NAME_MAP.put(StringUtils.upperCase(type.name()), type);
            ID_MAP.put(type.getId(), type);
        }
    }

    public static BackupTaskType fromChineseName(String chineseName) {
        return chineseName == null ? null : CHINESE_MAP.get(chineseName);
    }

    public static BackupTaskType fromName(String name) {
        return name == null ? null : NAME_MAP.get(StringUtils.upperCase(name));
    }

    public static BackupTaskType fromId(Integer id) {
        return id == null ? null : ID_MAP.get(id);
    }

}
